package org.testis.testdriver;

import org.testis.testdriver.exceptions.UnidentifiedTestPartException;
import org.testis.testdriver.parser.TestDriverAbstractParsingStrategy;
import org.testis.testdriver.parser.TestDriverDataObjectRefinedParsing;
import org.testis.testdriver.parser.TestDriverPostConditionCaseRefinedParsing;
import org.testis.testdriver.parser.TestDriverPreConditionCaseRefinedParsing;
import org.testis.testdriver.parser.TestDriverTestCaseGroupRefinedParsing;
import org.testis.testdriver.parser.TestDriverTestCaseRefinedParsing;
import org.testis.testdriver.parser.TestDriverTestPlanRefinedParsing;
import org.testis.testdriver.parser.TestDriverTestStepGroupRefinedParsing;
import org.testis.testdriver.parser.TestDriverTestStepRefinedParsing;
import org.testis.testdriver.parser.TestDriverTestSuiteRefinedParsing;
import org.orm.PersistentException;
import org.testis.orm.refinedclasses.DataObjectRefined;
import org.testis.orm.refinedclasses.PostConditionCaseRefined;
import org.testis.orm.refinedclasses.PreConditionCaseRefined;
import org.testis.orm.refinedclasses.TestCaseGroupRefined;
import org.testis.orm.refinedclasses.TestCaseRefined;
import org.testis.orm.refinedclasses.TestDesignTreeNode;
import org.testis.orm.refinedclasses.TestPlanRefined;
import org.testis.orm.refinedclasses.TestStepGroupRefined;
import org.testis.orm.refinedclasses.TestStepRefined;
import org.testis.orm.refinedclasses.TestSuiteRefined;


/**
 *
 * @author barisergun
 */
public class TestPlanParsingContext
{

    private TestDriverAbstractParsingStrategy testDriverParsingStrategy = null;


    public TestPlanParsingContext(ITestBuilder builder,
                                  TestDesignTreeNode currentNode)
    {
        if (currentNode.getObject() instanceof TestSuiteRefined) {

            testDriverParsingStrategy = new TestDriverTestSuiteRefinedParsing(
                builder,
                currentNode);
        }
        else if (currentNode.getObject() instanceof TestPlanRefined) {

            testDriverParsingStrategy = new TestDriverTestPlanRefinedParsing(
                builder,
                currentNode);
        }
        else if (currentNode.getObject() instanceof TestCaseGroupRefined) {

            testDriverParsingStrategy =
                new TestDriverTestCaseGroupRefinedParsing(builder,
                                                          currentNode);
        }
        else if (currentNode.getObject() instanceof TestCaseRefined) {

            testDriverParsingStrategy = new TestDriverTestCaseRefinedParsing(
                builder,
                currentNode);
        }
        else if (currentNode.getObject() instanceof PreConditionCaseRefined) {

            testDriverParsingStrategy =
                new TestDriverPreConditionCaseRefinedParsing(builder,
                                                             currentNode);
        }
        else if (currentNode.getObject() instanceof PostConditionCaseRefined) {
            
            testDriverParsingStrategy =  new TestDriverPostConditionCaseRefinedParsing(builder,
                                                              currentNode);
        }
        else if (currentNode.getObject() instanceof TestStepRefined) {
            
            testDriverParsingStrategy = new TestDriverTestStepRefinedParsing(
                builder,
                currentNode);
        }
        else if (currentNode.getObject() instanceof TestStepGroupRefined) {
            
            testDriverParsingStrategy = new TestDriverTestStepGroupRefinedParsing(builder,
                                                          currentNode);
        }
        else if (currentNode.getObject() instanceof DataObjectRefined) {
            
            testDriverParsingStrategy = new TestDriverDataObjectRefinedParsing(
                builder,
                currentNode);
        }
        else {
            throw new UnidentifiedTestPartException(
                "Unidentified Test Part in Test Plan Parsing");
        }

    }
    
    public void parseCurrentNode() throws PersistentException
    {
        testDriverParsingStrategy.parseCurrentNode();
    }
}
